/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package queenb.web.session;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ems
 */
public class PageController implements Serializable{
    private int totalrow; // tong so dong
    private int totalpage ; // tong so trang
    private int current; // traung hien tai
    static  private int numrow=20; // so dong tren 1 trang
    private int start; // bat dau lay tu record
    private int end; // lay tu record so

    private int startpage = 1; // page bat dau
    private int endpage = 10;   // page ket thuc
    private String pagename="";



    public PageController() {

    }



    /**
     * @return the current
     */
    public int getCurrent() {
        if(current > totalpage){
            current = totalpage;
        }else if(current < 1){
            current =1 ;
        }
        return current;
    }

    /**
     * @param current the current to set
     */
    public void setCurrent(int current) {
        if(current > totalpage){
            current = totalpage;
        }
        if(current < 1){
            current = 1;
        }
        start = (current-1)*getNumrow();
        end = current*numrow;
        this.current = current;
    }

    /**
     * @return the numrow
     */
    public int getNumrow() {
        if(numrow == 0){
            numrow = 20;
        }
        return numrow;
    }

    /**
     * @param numrow the numrow to set
     */
    public void setNumrow(int numrow) {
        this.numrow = numrow;
    }

    /**
     * @return the start
     */
    public int getStart() {
        if(start == 0){
            start = 1;
        }
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(int start) {
        this.start = start;
    }

    /**
     * @return the end
     */
    public int getEnd() {
        if(end == 0){
            end = 20;
        }
        return end;
    }

    /**
     * @param end the end to set
     */
    public void setEnd(int end) {
        this.end = end;
    }

    /**
     * @return the totalrow
     */
    public int getTotalrow() {
        return totalrow;
    }

    /**
     * @param totalrow the totalrow to set
     */
    public void setTotalrow(int totalrow) {
        if(totalrow == 0){
            totalrow = 100;
        }
        totalpage = totalrow / numrow;
        
        if(totalrow % numrow >0){
            totalpage = totalpage + 1;
        }

       
        if(getTotalpage() <= 10){
            setStartpage(1);
            setEndpage(getTotalpage());

        }else{
            setStartpage (current - 5);
            setStartpage ( current + 5);


        }
        this.totalrow = totalrow;
    }



    /**
     * @return the startpage
     */
    public int getStartpage() {
        if(startpage < 1){
            startpage =1;
        }
        return startpage;
    }

    /**
     * @param startpage the startpage to set
     */
    public void setStartpage(int startpage) {
        this.startpage = startpage;
    }

    /**
     * @return the endpage
     */
    public int getEndpage() {
        if(endpage > totalpage){
            endpage =totalpage;
        }
        return endpage;
    }

    /**
     * @param endpage the endpage to set
     */
    public void setEndpage(int endpage) {
        
        this.endpage = endpage;
    }

    /**
     * @return the totalpage
     */
    public int getTotalpage() {
        if(totalpage == 0){
            totalpage=10;
        }
        return totalpage;
    }

    /**
     * @param totalpage the totalpage to set
     */
    public void setTotalpage(int totalpage) {
        this.totalpage = totalpage;
    }

    /**
     * @return the pagename
     */
    public String getPagename() {
        return pagename;
    }

    /**
     * @param pagename the pagename to set
     */
    public void setPagename(String pagename) {
        this.pagename = pagename;
    }
}
